/*---------------------------------------------------------------------
 * File name: xmath.h
 *
 * Copyright (c) <2020-2022>, <ChenLong>
 *
 * All rights reserved.
 *
 * Author: ChenLong
 * Email: worldlong@foxmail.com
 *--------------------------------------------------------------------*/
#pragma once
/*
*/
#include <math.h>
/*
*/
#ifndef PI
#define PI      (3.1415926f)
#endif
#ifndef RAD2DEG
#define RAD2DEG (180.0f / PI)
#endif
#ifndef DEG2RAD
#define DEG2RAD (PI / 180.0f)
#endif
#define constrain(val, min, max) val = (val)>(max) ? (max) : ((val)<(min) ? (min) : (val))
#define round_pi(val) val = (val)>PI ? ((val)-2*PI) : ((val)<-PI ? (val)+2*PI : (val))
#define round_180(val) val = (val)>180 ? ((val)-360) : ((val)<-180 ? (val)+360 : (val))

/*
*/
template <typename  T>
void data_check(T &val, T def, T min, T max)
{
  if(isnan(val) || val < min || val > max) {
    val = def;
  }
}




